#include "fileutil.h"

int32_t FileUtil::is_normal_file( const char * name )
{
    return file_mode( name ) & S_IFREG;
}

int32_t FileUtil::is_dir( const char * name )
{
    return file_mode( name ) & S_IFDIR;
}

int32_t FileUtil::file_exist( const char * file )
{
    return 0 == ::access( file, F_OK );
}

int32_t FileUtil::file_size( const char * file )
{
    struct stat buf;
    if( 0 == ::stat( file, &buf ) )
        return buf.st_size;
    return -1;
}

time_t FileUtil::file_age( const char * file, E_FAGE age_type )
{
    struct stat buf;
    if( 0 == ::stat( file, &buf ) )
    {
        switch( age_type )
        {
        case E_CRT_TIME: return buf.st_ctime;
        case E_MOD_TIME: return buf.st_mtime;
        case E_ACC_TIME: return buf.st_atime;
        }
    }
    return (time_t)0;
}

int16_t FileUtil::file_mode( const char * file )
{
    struct stat buf;
    if( 0 == ::stat( file, &buf ) )
        return buf.st_mode;
    return 0;
}






